function loadEwhReqQueue() {
	$.ajax({
		type:		"POST",
		url:		"../EwhExportQueue/DisplayAjax?set_ajax_view",		
		dataType:   "json",	
		beforeSend: function() {
			$('div#phaEwhReqExpLoaderDiv').show();		
		},
		success: 	function(data) {
			if (data.error.code ==  'OK') {				
				$("table#tableWaitingQueue tbody").html(data.result.pending.body);
				$("table#tableWaitingQueue tr:last-child").addClass('last');
				$("table#tableWaitingQueue").trigger('update');
				//fillTotalTableData($('#waitingQueue'),data.result.pending.total_table);
				$("table#tableProcessedQueue tbody").html(data.result.processed.body);
				$("table#tableProcessedQueue tr:last-child").addClass('last');
				$("table#tableProcessedQueue").trigger('update');
				//fillTotalTableData($('#processedQueue'),data.result.processed.total_table);
											
			} else {
				displayError(data.error.mess);				
			}
			$('div#phaEwhReqExpLoaderDiv').hide();
		}
		});	
	
}

function fillTotalTableData(parentDiv, data) {
	$('table.total_table', parentDiv).remove();
	parentDiv.append(data);
	parentDiv.children('table:last-child').addClass('total_table');
}

function processRequest(requestId) {
	
	window.location =  "../EwhExportDrugMaterial/ProcessExpRequest?reqExTicketId=" + requestId;
	
}

function filterProcessedRequest() {
	
	window.location =  "../EwhExportQueue/DisplayProcessedRequestByFilter";
	

}

function doSearch() {
	if (!validateBeforeSearch()) {
    	return false;
	}
	var filterData = $("#filterForm").serialize();
	$.ajax({
        type:       "POST",
        url:        "../EwhExportQueue/DisplayProcessedRequestByFilterAjax?set_ajax_view",
        data:       filterData,      
        dataType:   "json",
        beforeSend: function() {
			$("#tableProcessedQueue tbody").html('');
		},
        success:    function(data) {

        if (data.error.code ==  'OK') {
            $("table#tableProcessedQueue tbody").html(data.result.processed.body);
			$("table#tableProcessedQueue tr:last-child").addClass('last');
			$("table#tableProcessedQueue").trigger('update');
			
           
        } else {
            displayError(data.error.mess);              
        }

    }
    }); 
}
function validateBeforeSearch() {
	$('#seachStatusMessage').html('');

    if ($.trim($('#reqTicketCodeFilter').val()) == ''
            && $.trim($('#fromDateFiltermm').val()) == ''
            && $.trim($('#fromDateFilterFilterdd').val()) == ''
            && $.trim($('#fromDateFilterFilteryyyy').val()) == ''
            && $.trim($('#toDateFiltermm').val()) == ''
            && $.trim($('#toDateFilterdd').val()) == ''
            && $.trim($('#toDateFilteryyyy').val()) == '')
    {
        $('#seachStatusMessage').html(_("Please enter search condition"));
        return false;
    }

    if (!($.trim($('#fromDateFiltermm').val()) == ''
        && $.trim($('#fromDateFilterdd').val()) == ''
            && $.trim($('#fromDateFilteryyyy').val()) == '')) {

        if (!checkDay($('#fromDateFilterdd'),true,'','#seachStatusMessage' )) {
            $('#seachStatusMessage').show();    
            return false;
        }   

        if (!checkMonth($('#fromDateFiltermm'),true,'','#seachStatusMessage')) {
            $('#seachStatusMessage').show();
            return false;
        } 

        var res     =   checkDate($('#fromDateFilteryyyy'),
                $('#fromDateFiltermm'),
                $('#fromDateFilterdd'), true, '', '#seachStatusMessage', false);
        if(!res){   
            $('#seachStatusMessage').show();
            return false;
        }
    }


    if (!($.trim($('#toDateFiltermm').val()) == ''
        && $.trim($('#toDateFilterdd').val()) == ''
            && $.trim($('#toDateFilteryyyy').val()) == '')) {

        if (!checkDay($('#toDateFilterdd'),true,'','#seachStatusMessage' )) {
            $('#seachStatusMessage').show();    
            return false;
        }   

        if (!checkMonth($('#toDateFiltermm'),true,'','#seachStatusMessage')) {
            $('#seachStatusMessage').show();
            return false;
        } 

        var res     =   checkDate($('#toDateFilteryyyy'),
                $('#toDateFiltermm'),
                $('#toDateFilterdd'), true, '', '#seachStatusMessage', false);  

        if(!res){   
            $('#seachStatusMessage').show();
            return false;
        }   
    }

    return true;
}     